$(document).ready(function() {
	
    let mainBottomSpan = $("#mainBottom span")
    mainBottomSpan.hover(function(){
    	$("#mainBottom span").css("opacity","0.7")
    },function(){
    	$("#mainBottom span").css("opacity","0")
    })
    mainBottomSpan.click(function(e) {
	    if($(this).css("opacity") != 0) {
	        $('#fileInput')[0].click();
	        e.stopPropagation();
	    }
	});
    
    $('#fileInput').on('change', function(e) {
        const fileInput = e.target;
        if (fileInput.files.length === 0) return;
        
        const formData = new FormData();
        formData.append('file', fileInput.files[0]); // 对应Servlet的Part名称
        
        updateHeadImg(formData);
    });
    
   /* $("section").on("click","#right>div:nth-of-type(2)>div",function(){
    	window.open("createCenter.html", "_blank");
    })*/
    
    
    addZY()
    rightHeight()
    numShow()
    function addZY(){
        $("section").html(`
            <div id="works">
                <div>
                    <button class="buttonActive">粉丝视角</button>
                    <button>新访客视角</button>
                </div>
                <div>
                    <img src="img/works.webp">
                    <div class="text-content">
                        <p>置顶视频是粉丝们看到的第一个视频，</p>
                        <p>请选择你最喜欢的作品，让粉丝们一饱眼福吧！</p>
                        <button class="buttonActive">+置顶视频</button>
                    </div>
                </div>
            </div>
            <div id="collect">
                <div>收藏夹</div><span>&nbsp; · &nbsp;<span>1</span></span>
                <button>查看更多></button>
                <div>
                    <img src="">
                    <div><span></span>个视频</div>
                    <div>
                        <p>默认收藏夹</p>
                        <p>公开</p>
                    </div>
                </div>
            </div>
        `
        )

        $("#works div").eq(0).find("button").hover(function(){
            if(!$(this).hasClass("buttonActive")){
                $(this).addClass("buttonHover")
            }
        },function(){
            $(this).removeClass("buttonHover")
        })
        $("#works div").eq(0).find("button").click(function(e){
            if($(this).text() == "粉丝视角"){
                $(this).siblings().removeClass("buttonActive")
                $(this).addClass("buttonActive")
                $("#works div").eq(1).find("p").eq(0).text("置顶视频是粉丝们看到的第一个视频，")
                $("#works div").eq(1).find("p").eq(1).text("请选择你最喜欢的作品，让粉丝们一饱眼福吧！")
                $("#works div").eq(1).find("button").text("+置顶视频")
            }else if($(this).text() == "新访客视角"){
                $(this).siblings().removeClass("buttonActive")
                $(this).addClass("buttonActive")
                $("#works div").eq(1).find("p").eq(0).text("代表作是新访客看到的第一个视频，")
                $("#works div").eq(1).find("p").eq(1).text("选择你的得意之作，吸引新访客立即关注你吧！")
                $("#works div").eq(1).find("button").text("+代表作视频")
            }
        })
        
        collectDisplay()
    }

    /*function addDT(){
        $("section").html(`
            <div id="DT">
                <button class="btnBGC">全部</button>
                <button>视频</button>
                <div>
                    <img src="img/ZFZJ.svg">
                    <p>好像没有东西欸</p>
                </div>
            </div>
            <div id="right">
                <div>
                    <p>点此申请cilicili认证</p>
                    <p>获得认证，享受多重认证福利！</p>
                </div>
                <div><div>创作中心></div><br><button>视频投稿</button><button>投稿管理</button></div>
                <div>
                    <div>
                        公告
                        <textarea placeholder="编辑我的公告" maxlength="150"></textarea>
                    </div>
                </div>
                <div>
                    <div>
                        <div>
                            个人资料
                            <a href="#">编辑></a>
                        </div>
                        <img src="img/UID.png">
                        <p>11111111</p>
                        <br>
                        <img src="img/birthday.png">
                        <p></p>
                    </div>
                </div>
            </div>
        `)
        
        $("#DT").on("click","button",function(){
            $("#DT button").each(function(){
                $(this).removeClass("btnBGC")
            })
            $(this).addClass("btnBGC")
        })
    }*/

    function addTG(){
        $("section").html(`
            <div id="TG">
                <button class="TGbtnBGC">视频<span>0</span></button>
                <p id="TGserch">
                	<b>我的视频</b>
	                <input type="text" placeholder="输入关键词">
	                <img src="img/SSTitle.png">
                </p>
                <div>
                    <img src="img/TG.svg">
                    <p>快来上传视频，成为UP主吧！</p>
                    <p>同时直播中会优先展示你的直播间</p>
                    <button>上传视频</button>
                </div>
            </div>
        `)
        
        $("#TG>div>button").click(function(){
        	window.open("createCenter.html", "_blank");
        })
        
        $("#TG #TGserch>img").click(function(){
        	queryMyVideo()
        })
        
        $("#TG>div").on("click","img",function(){
        	videoJumpTo($(this).next().find("input").val())
	    })
	    $("#TG>div").on("click","p:first-of-type",function(){
	    	videoJumpTo($(this).prev().find("input").val())
	    })
    }
    
    
    function addZFZJ(){
        $("section").html(`
            <div id="ZFZJ">
                <button class="ZFZJbtnBGC">追番<span>0</span></button>
                <button>追剧<span>0</span></button>
                <div>
                    <div>追番</div>
                    <button class="ZFZJDIVbtnBGC">全部</button>
                    <button>想看</button>
                    <button>在看</button>
                    <button>看过</button>
                </div>
                <div>
                    <img src="img/ZFZJ.svg">
                    <p>还没有追任何一部番呢 （：'⌒'）</p>
                </div>
            </div>
        `)
        $("#ZFZJ>button").click(function(){
            let index = $(this).index()
            $("#ZFZJ button").each(function(){
                $(this).removeClass("ZFZJbtnBGC")
            })
            $("#ZFZJ>div:first-of-type>button").each(function(){
                $(this).removeClass("ZFZJDIVbtnBGC")
            })
            $("#ZFZJ>div:first-of-type>button").eq(0).addClass("ZFZJDIVbtnBGC")
            $(this).addClass("ZFZJbtnBGC")
            if(index == 0){
                $("#ZFZJ>div:first-of-type>div").text("追番")
                $("#ZFZJ>div:last-of-type>p").text("还没有追任何一部番呢 （：'⌒'）")
            }else if(index == 1){
                $("#ZFZJ>div:first-of-type>div").text("追剧")
                $("#ZFZJ>div:last-of-type>p").text("还没有追任何一部剧呢 （：'⌒'）")
            }
        })
        $("#ZFZJ>div:first-of-type>button").click(function(){
            let $this = $(this).text()
            let $p = $("#ZFZJ>div:last-of-type>p")
            $("#ZFZJ button").each(function(){
                if($(this).hasClass("ZFZJbtnBGC")){
                    if($this == "全部"){
                        if($(this).text().includes("追剧")){
                            $p.text("还没有追任何一部剧呢 （：'⌒'）")
                        }else if($(this).text().includes("追番")){
                            $p.text("还没有追任何一部番呢 （：'⌒'）")
                        }
                    }else if($this == "想看"){
                        if($(this).text().includes("追剧")){
                            $p.text("没有任何想看的剧呢 （：'⌒'）")
                        }else if($(this).text().includes("追番")){
                            $p.text("没有任何想看的番呢 （：'⌒'）")
                        }
                    }else if($this == "在看"){
                        if($(this).text().includes("追剧")){
                            $p.text("没有任何一部剧正在看呢 （：'⌒'）")
                        }else if($(this).text().includes("追番")){
                            $p.text("没有任何一部番正在看呢  （：'⌒'）")
                        }
                    }else if($this == "看过"){
                        if($(this).text().includes("追剧")){
                            $p.text("还没有看完过一部剧 （：'⌒'）")
                        }else if($(this).text().includes("追番")){
                            $p.text("还没有看完过一部番 （：'⌒'）")
                        }
                    }
                }
            })
            $("#ZFZJ>div:first-of-type>button").each(function(){
                $(this).removeClass("ZFZJDIVbtnBGC")
            })
            $(this).addClass("ZFZJDIVbtnBGC")
        })
    }

    function addGZ(){
        $("section").html(`
            <div id="GZ">
                <div>我的关注</div>
                <div>
                    <ul>
                        <li class="liActive">
                            <img src="img/GZ.png">
                            全部关注
                            <span></span>
                        </li>
                    </ul>
                </div>
                <div>
                    <div>我的粉丝</div>
                    <div id="GZDiv"><img src="img/FS.png">我的粉丝<span></span></div>
                </div>
                <footer>
                    <div>
                        全部关注
                    </div>
                    <div>
                        <input type="text" placeholder="输入关键词"><img src="img/SSTitle.png">
                    </div>
                    <div>
                        <ul>
                            
                        </ul>
                    </div>
                </footer>
            </div>
        `)
        $("#GZ>div li").click(function(){
            $("#GZ>div:last-of-type>div:last-of-type").removeClass("liActive")
            $("#GZ>div:last-of-type>div:last-of-type").css("background-color","transparent")
            $(this).addClass("liActive")
            $(this).removeClass("GZLihover")
            $("#GZ>footer>div:first-of-type").text("全部关注")
            queryMyAttention()
            $("#middle>ul:last-child li").eq(0).css("color","#00AEEC")
            $("#middle>ul:last-child li").eq(1).css("color","black")
        })

        $("#GZ>div li").hover(function(){
            if(!$(this).hasClass("liActive")){
                $(this).addClass("GZLihover")
            }
        },function(){
            $(this).removeClass("GZLihover")
        })

        $("#GZ>div:last-of-type>div:last-of-type").click(function(){
            $("#GZ>div li").removeClass("liActive")
            $(this).addClass("liActive")
            $(this).css("background-color","#00AEEC")
            $("#GZ>footer>div:first-of-type").text("全部粉丝")
            queryAttentionToMe()
            $("#middle>ul:last-child li").eq(1).css("color","#00AEEC")
            $("#middle>ul:last-child li").eq(0).css("color","black")
        })

        $("#GZ>div:last-of-type>div:last-of-type").hover(function(){
            if(!$(this).hasClass("liActive")){
                $(this).css("background-color","#F6F7F8")
            }
        },function(){
            if(!$(this).hasClass("liActive")){
                $(this).css("background-color","transparent")
            }
        })

        $("#GZ>footer>div:nth-of-type(2)>img").click(function(){
        	if($("#GZ>footer>div:first-of-type").text() == "全部关注"){
            	queryMyAttention()
        	}else{
            	queryAttentionToMe()
        	}
        })
        
        $("#GZ>footer>div:last-of-type>ul").on("click","button",function(){
    		let value = $(this).parent().find("input").val()
        	if($("#GZ>footer>div:first-of-type").text() == "全部关注"){
	        	if($(this).text() == "关注"){
	        		let $this = $(this)
	        		$(this).removeClass("notActiveBtn")
	        		isFollowIsMutual(value,-1,function(result) {
	        			if(result){
	        				$this.text("互相关注")
	        			}else{
	        				$this.text("已关注")
	        			}
	        		})
	        		addMyAttention(value)
	        	}else{
	        		$(this).addClass("notActiveBtn");
	        		$(this).text("关注")
	        		removeMyAttention(value)
	        	}
        	}else{
        		if($(this).text() == "关注"){
	        		$(this).removeClass("notActiveBtn")
    				$(this).text("互相关注")
	        		addMyAttention(value)
	        	}else{
	        		$(this).addClass("notActiveBtn");
	        		$(this).text("关注")
	        		removeMyAttention(value)
	        	}
        	}
    		numShow()
        })
    }

    function addSC(){
        $("section").html(`
            <div id="SC">
                <button><img src="img/SCJ.png">默认收藏夹<span></span></button>
                <div>
                    <img src="">
                    <div>
                        <div>
                            默认收藏夹
                            <p>
                                视频数：
                                <span></span>
                            </p>
                        </div>
                        <button>播放全部</button>
                    </div>
                </div>
                <div>
                    <div>
                        <button>最近收藏</button>
                        <div id="serch">
	                        <input type="text" placeholder="输入关键词">
	                        <img src="img/SSTitle.png">
                        </div>
                        </span>
                    </div>
                    <div>
                        <ul>
                            
                        </ul>
                    </div>
                </div>
            </div>
        `)
        setInterval(function(){
            $("#SC>div:first-of-type>img").prop("src",$("#SC>div:last-of-type>div:last-of-type li").eq(0).find("img").prop("src"))
        })
        $("#SC>div:last-of-type>div:last-of-type li>img").hover(function(){
            $(this).parent().find("div").css("opacity","0")
        },function(){
            $(this).parent().find("div").css("opacity","1")
        })
        
	    
	    $("#SC #serch").on("click","img",function(){
	    	collectDisplay()
	    })
	    
	    $("#SC>div:last-of-type>div:last-of-type").on("click","img",function(){
        	videoJumpTo($(this).next().find("input").val())
	    })
	    $("#SC>div:last-of-type>div:last-of-type").on("click","p:first-of-type",function(){
	    	videoJumpTo($(this).prev().find("input").val())
	    })
        
    }
    
    $("#middle ul").eq(0).find("li").click(function(){
        let text = $(this).text()
        if(text == "主页"){
            $("section").empty();
            addZY()
            //rightHeight()
            userDisplay()
        }else if(text == "动态"){
            /*$("section").empty();
            addDT()
            rightHeight()
            userDisplay()*/
        }else if(text == "投稿"){
            $("section").empty()
            addTG()
            numShow()
            queryMyVideo()
        }else if(text == "收藏"){
            $("section").empty()
            addSC()
            collectDisplay()
        }else if(text == "追番追剧"){
            $("section").empty()
            addZFZJ()
        }
    })

    $("#middle>ul:last-child li").click(function(){
    	if($(this).index() < 2){
	        numShow()
	        addGZ()
	        if($(this).index() == 0){
	        	$("#GZ>div li").click()
	        }else if($(this).index() == 1){
	            $("#GZ>div:last-of-type>div:last-of-type").click()
	        }
	        numShow()
    	}
    })
    $("#middle>ul:last-child li").each(function(){
    	if($(this).index() >= 2){
    		$(this).css("cursor","text")
    	}
    })
    $("#middle>ul:last-child li").hover(function(){
    	if($(this).index() >= 2){
    		$(this).css("color","black")
    	}
    })
    
    function rightHeight(){
        let divHeight = [85,122,232,126]
        $("#right>div").each(function(index){
            $(this).css("height",divHeight[index]+"px")
        })
    }

    /*$("#mainBottom input").focus(function(){
        $(this).css({
            "outline":"none",
            "background-color":"white",
            "color":"black"
        })
    })
    $("#mainBottom input").blur(function(){
        $(this).css({
            "outline":"none",
            "background-color":"transparent",
            "color":"white"
        })
    })*/
    $("#middle > ul:first-child li").click(function(){
        if($(this).index()<$("#middle > ul:first-child li").length-1){
            $("#middle > ul:first-child li").each(function(){
                $(this).removeClass("activeLi")
            })
            $(this).addClass("activeLi")
        }
    })
    

    function zan4ding4(){
        `
        <div id="thumbs-up">
            <div>最近点赞视频</div>
            <ul>
                <li>
                    <img src="img/1.jpg">
                    
                    <div>
                        <span><img src="img/BF.png">播放量</span>
                        <span><img src="img/PL.png">评论量</span>
                        <span>时长</span>
                    </div>
                    <p>视频标题</p>
                    <p>博主</p>
                </li>
                <li>
                    <img src="img/1.jpg">
                    <div>
                        <span>播放量</span>
                        <span>评论量</span>
                        <span>时长</span>
                    </div>
                    <p>视频标题</p>
                    <p>博主</p>
                </li>
                <li>
                    <img src="img/1.jpg">
                    <div>
                        <span>播放量</span>
                        <span>评论量</span>
                        <span>时长</span>
                    </div>
                    <p>视频标题</p>
                    <p>博主</p>
                </li>
                <li>
                    <img src="img/1.jpg">
                    <div>
                        <span>播放量</span>
                        <span>评论量</span>
                        <span>时长</span>
                    </div>
                    <p>视频标题</p>
                    <p>博主</p>
                </li>
                <li>
                    <img src="img/1.jpg">
                    <div>
                        <span>播放量</span>
                        <span>评论量</span>
                        <span>时长</span>
                    </div>
                    <p>视频标题</p>
                    <p>博主</p>
                </li>
                <li>
                    <img src="img/1.jpg">
                    <div>
                        <span>播放量</span>
                        <span>评论量</span>
                        <span>时长</span>
                    </div>
                    <p>视频标题</p>
                    <p>博主</p>
                </li>
                <li>
                    <img src="img/1.jpg">
                    <div>
                        <span>播放量</span>
                        <span>评论量</span>
                        <span>时长</span>
                    </div>
                    <p>视频标题</p>
                    <p>博主</p>
                </li>
                <li>
                    <img src="img/1.jpg">
                    <div>
                        <span>播放量</span>
                        <span>评论量</span>
                        <span>时长</span>
                    </div>
                    <p>视频标题</p>
                    <p>博主</p>
                </li>
                <li>
                    <img src="img/1.jpg">
                    <div>
                        <span>播放量</span>
                        <span>评论量</span>
                        <span>时长</span>
                    </div>
                    <p>视频标题</p>
                    <p>博主</p>
                </li>
                <li>
                    <img src="img/1.jpg">
                    <div>
                        <span>播放量</span>
                        <span>评论量</span>
                        <span>时长</span>
                    </div>
                    <p>视频标题</p>
                    <p>博主</p>
                </li>
            </ul>
        </div>
        
        
        
        <div id="right">
                <div>
                    <p>点此申请cilicili认证</p>
                    <p>获得认证，享受多重认证福利！</p>
                </div>
                <div><div>创作中心></div><br><button>视频投稿</button><button>投稿管理</button></div>
                <div>
                    <div>
                        公告
                        <textarea placeholder="编辑我的公告" maxlength="150"></textarea>
                    </div>
                </div>
                <div>
                    <div>
                        <div>
                            个人资料
                            <a href="#">编辑></a>
                        </div>
                        <img src="img/UID.png">
                        <p>11111111</p>
                        <br>
                        <img src="img/birthday.png">
                        <p></p>
                    </div>
                </div>
            </div>
        `
    }

    $("#middle>ul:last-child li").click(function(){
        if($(this).index() < 2){
            $("#middle li").each(function(){
                $(this).removeClass("activeLi")
            })
        }
    })

    $("#middle>ul:first-child li").click(function(){
        $("#middle>ul:last-child li").each(function(){
            $(this).css("color","black")
        })
    })

    $("section").on("click","#collect img",function(){
    	
        addSC()
        liChange()
        collectDisplay()
    })
    $("section").on("click","#collect>div:last-of-type>div:last-of-type>p:first-of-type",function(){
        addSC()
        liChange()
        collectDisplay()
    })

    $("section").on("click","#collect button",function(){
        addSC()
        liChange()
        collectDisplay()
    })
    $("section").on("click","#collect div:first-of-type",function(){
        addSC()
        liChange()
        collectDisplay()
    })
    $("#three li").find("a").click(function(e){
        
        if($(this).text().replace(/\s+/g, '') == "收藏"){
            e.preventDefault();
            addSC()
            liChange()
            collectDisplay()
        }
    })
    function liChange(){
        $("#middle > ul:first-child>li").each(function(){
            $(this).removeClass("activeLi")
            if($(this).text() == "收藏"){
                $(this).addClass("activeLi")
            }
        })

    }

    let queryParams = new URLSearchParams(window.location.search)
    if(queryParams.get('collect') == 0){
        addSC()
        liChange()
        collectDisplay()
    }
    
    $("#three li:first-of-type>a").click(function(e){
    	e.preventDefault();
    })
    
    
 // ----------------↑页面----------------↓ajax----------------
    
    

    let logVariableQatm = [1],logVariableQmv = [1],logVariableQma = [1],logVariableCd = [1];
    userDisplay()
    function userDisplay(){
    	$.ajax({
    		url:"id",
    		type:"post",
    		success:function(data){
    			if(data.code == 200){
	    			let userHeadImg = data.data.avatarUrl
	    			$("#three li:first-of-type img").prop("src",userHeadImg)
	    			$("#mainBottom img").prop("src",userHeadImg)
	    			$("#mainBottom>div>div:first-of-type").text(data.data.nickname)
	    			//$("#right>div:last-of-type>div>p").eq(1).text(data.data.birthday.split("-").slice(1).join("-"))
    			}
    		}
    	})
    }
    

    collectDisplay()
    function collectDisplay(pageNum = 1){
    	let divBig = $("#SC>div:last-of-type>div:last-of-type")
    	let title = $("#SC #serch>input").val()
		let ul = $("#SC>div:last-of-type>div:last-of-type>ul")
    	$.ajax({
    		url:"user/collect",
    		type:"post",
    		data:{
    			pageNum:pageNum,
    			title:title
    		},
    		success:function(data){
    			if(data.code == 200){
	    			let collect = data.data.data
	    			numShow()
	    			$("#collect img").prop("src",collect[0].coverUrl)
	    			ul.empty();
	    			for(let i = 0;i<collect.length;i++){
		    			let totalTime = countVideoTime(collect[i].duration)
	    				let li = `
	    					<li>
	                            <img src="${collect[i].coverUrl}">
	                            <div>
	                            	<input type="hidden" value="${collect[i].videoId}">
	                                <span><img src="img/BF.png">${countVideoNum(video.viewCount)}</span>
	    							<span><img src="img/PL.png">${countVideoNum(video.commentNum)}</span>
	                                <span>${totalTime}</span>
	                            </div>
	                            <p>${collect[i].title}</p>
	                            <p><label style="cursor: pointer;"><img src="img/BZ.png">${collect[i].nickname}</label>&nbsp;·&nbsp;收藏于<span>${collect[i].collection_time}</span></p>
	                        </li>
	    				`
	    					ul.append(li)
	    			}
	    			if(data.data.totalRows > 15){
		    			$("#pageBar").remove();
		    			let div = `<div id="pageBar"></div>`
						divBig.append(div)
		    			makePageBar(data.data,collectDisplay,logVariableCd)
	    			}
    			}else{
    				ul.text("没有找到哦~")
    			}
    		}
    	})
    }
    
    function queryMyAttention(pageNum = 1){
		let divBig = $("#GZ>footer>div:last-of-type")
		let ul = $("#GZ>footer>div:last-of-type>ul")
		let inputValue = $("#GZ>footer>div:nth-of-type(2)>input").val()
    	$.ajax({
    		url:"MyAttention",
    		type:"post",
    		data:{
    			pageNum:pageNum,
    			nickName:inputValue
    		},
    		success:function(data){
    			if(data.code == 200){
	    			let users = data.data.data
	    			ul.empty()
	    			for(let i = 0;i<users.length;i++){
						let user = users[i]
						let li;
					    isFollowIsMutual(user.userId,-1,function(result) {
							if(result){
								li = `
									<li>
			                            <img src="${user.avatarUrl}">
			                            <div>
											<input type="hidden" value="${user.userId}">
			                                <p>${user.nickname}</p>
			                                <p>这个人没有填简介啊~~~</p>
			                                <button>互相关注</button>
			                            </div>
			                        </li>
								`
							}else{
								li = `
									<li>
			                            <img src="${user.avatarUrl}">
			                            <div>
			                            	<input type="hidden" value="${user.userId}">
			                                <p>${user.nickname}</p>
			                                <p>这个人没有填简介啊~~~</p>
			                                <button>已关注</button>
			                            </div>
			                        </li>
								`
							}
							ul.append(li)
					    })
					}
	    			if(data.data.totalRows > 9){
		    			$("#pageBar").remove();
		    			let div = `<div id="pageBar"></div>`
						divBig.append(div)
		    			makePageBar(data.data,queryMyAttention,logVariableQma)
	    			}
    			}else{
    				ul.text("没有找到哦~")
    			}
    		}
    	})
    }
    
    function queryAttentionToMe(pageNum = 1){
    	let divBig = $("#GZ>footer>div:last-of-type")
    	let ul = $("#GZ>footer>div:last-of-type>ul")
    	let inputValue = $("#GZ>footer>div:nth-of-type(2)>input").val()
    	$.ajax({
    		url:"AttentionToMe",
    		type:"post",
    		data:{
    			pageNum:pageNum,
    			nickName:inputValue
    		},
    		success:function(data){
    			if(data.code == 200){
	    			let users = data.data.data
	    			ul.empty()
	    			for(let i = 0;i<users.length;i++){
						let user = users[i]
						let li;
						isFollowIsMutual(-1,user.userId,function(result) {
							if(result){
								li = `
									<li>
			                            <img src="${user.avatarUrl}">
			                            <div>
			                            	<input type="hidden" value="${user.userId}">
			                                <p>${user.nickname}</p>
			                                <p>这个人没有填简介啊~~~</p>
			                                <button>互相关注</button>
			                            </div>
			                        </li>
								`
							}else{
								li = `
									<li>
			                            <img src="${user.avatarUrl}">
			                            <div>
			                            	<input type="hidden" value="${user.userId}">
			                                <p>${user.nickname}</p>
			                                <p>这个人没有填简介啊~~~</p>
			                                <button class="notActiveBtn">关注</button>
			                            </div>
			                        </li>
								`
							}
							ul.append(li)
					    })
					}
	    			if(data.data.totalRows > 9){
		    			$("#pageBar").remove();
		    			let div = `<div id="pageBar"></div>`
						divBig.append(div)
		    			makePageBar(data.data,queryAttentionToMe,logVariableQatm)
	    			}
    			}else{
    				ul.text("没有找到哦~")
    			}
    		}
    	})
    }

    function queryMyVideo(pageNum = 1){
    	currentPage = 1;
    	let divBig = $("#TG>div")
    	let inputValue = $("#TG #TGserch>input").val()
    	$.ajax({
    		url:"queryMyAllVideo",
    		type:"post",
    		data:{
    			pageNum:pageNum,
    			title:inputValue
    		},
    		success:function(data){
    			if(data.code == 200){
	    			divBig.empty()
    				divBig.css("left", "90px");
	    			let videos = data.data.data
	    			let ul = $("<ul></ul>")
    				for(let i = 0;i<videos.length;i++){
    					let video = videos[i]
		    			let totalTime = countVideoTime(video.duration)
	    				let li = `
	    					<li>
	                            <img src="${video.coverUrl}">
	                            <div>
	                            	<input type="hidden" value="${video.videoId}">
	                                <span><img src="img/BF.png">${countVideoNum(video.viewCount)}</span>
	    							<span><img src="img/PL.png">${countVideoNum(video.commentNum)}</span>
	                                <span>${totalTime}</span>
	                            </div>
	                            <p>${video.title}</p>
	                            <p>${video.createTime}</p>
	                        </li>
	    				`
	    					ul.append(li)
	    			}
    				divBig.append(ul)
    				if(data.data.totalRows > 15){
		    			$("#pageBar").remove();
		    			let div = `<div id="pageBar"></div>`
						divBig.append(div)
		    			makePageBar(data.data,queryMyVideo,logVariableQmv)
    				}else{
    					$("#TG>div>ul").css("height","0px")
    				}
    			}
    		}
    	})
    }

    // 格式化视频数量（超过1万显示为x.x万）
    function countVideoNum(videoNum) {
        if (videoNum >= 10000) {
            const formatted = (videoNum / 10000).toString();
            return formatted.replace(/(\.\d)\d*/, '$1') + '万'; // 保留一位小数
        }
        return videoNum.toString();
    }
    
    function numShow(){
    	$.ajax({
    		url:"MyAttention",
    		type:"post",
    		success:function(data){
    			if(data.data != null){
					$("#GZ>div:nth-last-of-type(2) li>span").text(data.data.totalRows)
					$("#middle>ul:last-child li").eq(0).html(`关注数<br>${data.data.totalRows}`)
    			}else{
    				$("#GZ>div:nth-last-of-type(2) li>span").text(0)
					$("#middle>ul:last-child li").eq(0).html(`关注数<br>0`)
    			}
    			
    		}
    	})
    	$.ajax({
    		url:"AttentionToMe",
    		type:"post",
    		success:function(data){
				$("#GZ>div:last-of-type>div:last-of-type>span").text(data.data.totalRows)
				$("#middle>ul:last-child li").eq(1).html(`粉丝数<br>${data.data.totalRows}`)
    		}
    	})
    	$.ajax({
    		url:"user/collect",
    		type:"post",
    		success:function(data){
    			if(data.code == 200){
	    			$("#collect>div:last-of-type>div:first-of-type>span").text(data.data.totalRows)
	    			$("#SC>button>span").text(data.data.totalRows)
	    			$("#SC>div:first-of-type>div>div>p>span").text(data.data.totalRows)
    			}
    		}
    	})
    	$.ajax({
    		url:"queryMyAllVideo",
    		type:"post",
    		success:function(data){
    			if(data.code == 200){
    				$("#TG>button>span").text(data.data.totalRows)
    				let totalLikeCount = 0,totalViewCount = 0;
    				let videos = data.data.data
    				for(let i = 0;i<videos.length;i++){
    					let video = videos[i]
    					totalLikeCount+=video.likeCount
    					totalViewCount+=video.viewCount
    				}
    				if(totalLikeCount >= 10000){
    					totalLikeCount = totalLikeCount/10000+"万"
    				}
    				if(totalViewCount >= 10000){
    					totalViewCount = totalViewCount/10000+"万"
    				}
    				$("#middle>ul:last-child li").eq(2).html(`获赞数<br>${totalLikeCount}`)
    				$("#middle>ul:last-child li").eq(3).html(`播放数<br>${totalViewCount}`)
    			}
    		}
    	})
    }

    function makePageBar(page,ifoName,variable) {
	    let pageBar = $("#pageBar");
	    let navigatorNums = page.totalPageNum;
	    pageBar.empty();
	
	
	    if (page.hasPrev) {
	        let prevPage = $("<button class='prev'>上一页</button>").click(function() {
	        	ifoName(variable[0] - 1);
	        	variable.push(variable[0] - 1)
	        	variable.shift()
	        });
	        pageBar.append(prevPage);
	    }
	
	    for (let i = 0; i < navigatorNums.length; i++) {
	        let num = navigatorNums[i];
	        let pageLink = $("<button>" + num + "</button>").click(function() {
	        	ifoName(num);
	        	variable.push(num)
	        	variable.shift()
	        });
	        pageBar.append(pageLink);
	    }
	
	    if (page.hasNext) {
	        let nextPage = $("<button class='next'>下一页</button>").click(function() {
	        	ifoName(variable[0]+1);
	        	variable.push(variable[0]+1)
	        	variable.shift()
	        });
	        pageBar.append(nextPage);
	    }
	    $("#pageBar button").each(function(){
	    	if($(this).text() == variable[0]){
	    		$(this).addClass("styleA");
	    	}
	    })
	
	    $("#pageBar").css("width", 90 * $("#pageBar button").length + "px");
	}
    
    function isFollowIsMutual(follower,followee,isBoolean){
    	$.ajax({
    		url:"FollowIsMutual",
    		type:"post",
    		data:{
    			follower_id:follower,
    			followee_id:followee
    		},
    		success:function(data){
    			if(data.code == 200){
    				isBoolean(true);
    			}else{
    				isBoolean(false);
    			}
    		}
    	})
    }
    
    function addMyAttention(followee){
    	$.ajax({
    		url:"addMyAttention",
    		type:"post",
    		data:{
    			followee_id:followee
    		},
    		success:function(data){
    			if(data.code == 200){
    				promptAnimation("关注成功")
    				queryMyAttention()
    				numShow()
    			}else{
    				promptAnimation("关注失败")
    			}
    		}
    	})
    }
    
    function removeMyAttention(followee){
    	$.ajax({
    		url:"removeMyAttention",
    		type:"post",
    		data:{
    			followee_id:followee
    		},
    		success:function(data){
    			if(data.code == 200){
    				promptAnimation("取消关注成功")
    				if($("#GZ>footer>div:first-of-type").text() == "全部关注"){
    					queryMyAttention()
    				}else{
        				queryAttentionToMe()
    				}
    				numShow()
    			}else{
    				promptAnimation("取消关注失败")
    			}
    		}
    	})
    }
    
    
    function updateHeadImg(formData) {
        $.ajax({
            url: "updateHeadImg",
            type: "POST",
            data: formData,
            contentType: false, // 必须false才会自动处理
            processData: false, // 必须false才会自动处理
            success: function(data) {
                if (data.code == 200) {
                    promptAnimation("修改头像成功")
                    userDisplay(); // 刷新用户信息
                } else {
                	promptAnimation(data.massage)
                }
            }
        });
    }
    
    function promptAnimation(text) {
        let $prompt = $("#prompt");
        // 确保元素回到初始位置
        $prompt.css("top", "-60px");
        $prompt.text(text)
        // 上升动画
        $prompt.animate({ top: 0 }, {
            duration: 240,  // 60px / (5px/20ms) = 240ms
            easing: "linear",
            complete: function() {
                // 等待1秒后执行下降动画
                setTimeout(function() {
                    // 下降动画
                    $prompt.animate({ top: -60 }, {
                        duration: 240,
                        easing: "linear"
                    });
                }, 1500);
            }
        });
    }
    
    function countVideoTime(totalSecond){
    	let hous = parseInt(totalSecond/60/60)
		let minute = parseInt((totalSecond - hous*60*60)/60)
		let second = totalSecond - hous*60*60 - minute*60
		if(hous < 10){
			hous = "0"+hous
		}
		if(minute < 10){
			minute = "0"+minute
		}
		if(second < 10){
			second = "0"+second
		}
		let totalTime;
		if(hous == 0){
			totalTime = minute+":"+second
		}else{
			totalTime = hous+":"+minute+":"+second
		}
		return totalTime;
    }
    

    function videoJumpTo(videoId) {
  	  $.ajax({
  	    url: "selectVideo.do",
  	    type: "GET",
  	    data: { 
  	    	action:"send",
  	    	videoId: videoId 
  	    	},
  	    success: function() {
  	        localStorage.setItem('pendingVideoId', videoId);
  	        window.open("video.html", "_blank");
  	    }
  	  });
  	}
})